#include <list>
#include <string>
#include <iostream>

#include "special_element.h"

using namespace std;

SpecialElement::SpecialElement (string aName, Parameter aParam) : BaseElement(aName), param(aParam) {
}

SpecialElement::~SpecialElement () {
}

bool SpecialElement::isParentOf (BaseElement & e) {
	return false;
}

string SpecialElement::generateRegex(DoctypeDefinition* dtd) {
	// TODO handle namespaces
	string tag = "<" + name + "[:alnum:=\"]*";
	string endTag = "</" + name + ">";
	switch (param) {
		
		case EMPTY:
			
			tag+="(/>|>"+endTag+")";
			return tag;
			
		default: // ANY
			tag+=">[^<]*"+endTag;
			return tag;
	};
}

void SpecialElement::print(ostream& out) {
	switch (param) {
	
		case EMPTY:
			out << "<!ELEMENT " << name << " EMPTY>\n";
			break;
		default: // ANY
			out << "<!ELEMENT " << name << " ANY>\n";
			break;
	};
	
	printAttributes(out);
}
